
#ifndef	MESSENGER_HPP
#define	MESSENGER_HPP

#include <queue>
#include <boost/unordered_map.hpp>
#include <boost/signals2.hpp>
#include <boost/shared_ptr.hpp>

class base_message_data
{
public:
	virtual ~base_message_data( ) { }

protected:
	base_message_data( ) { }
};

typedef boost::shared_ptr<base_message_data const> message_data_ptr;

class messenger
{
public:

	typedef boost::signals2::signal< void ( std::string const & message, message_data_ptr data ) > listeners_t;
	typedef boost::shared_ptr< listeners_t > listeners_ptr_t;
	typedef listeners_t::slot_type slot_t;
	typedef boost::signals2::connection connection_t;

	void push( std::string const & message, message_data_ptr data );
	connection_t add_listener( std::string const & message, slot_t const & slot );

	void poll( );
	
private:

	typedef boost::signals2::signal< void ( std::string const & message, message_data_ptr data ) > listeners_t;
	typedef boost::unordered_map< std::string, listeners_ptr_t > listeners_map_t;

	typedef std::pair< std::string, message_data_ptr > message_t;
	typedef std::queue< message_t > message_queue_t;

	message_queue_t m_message_queue;
	listeners_map_t m_listeners;
};

extern messenger g_messenger;

#endif	//MESSENGER_HPP
